Skip to content

chore(api): add auth attributes#2120

Merged
jakubno merged 9 commits intomainfrom
chore/improve-identification-in-logs
Mar 17, 2026
Merged

chore(api): add auth attributes#2120
jakubno merged 9 commits intomainfrom
chore/improve-identification-in-logs

Conversation

@jakubno
Copy link
Member

@jakubno jakubno commented Mar 12, 2026

image

Note

Medium Risk
Touches authentication validation call paths and logging/telemetry context propagation; mistakes could break auth middleware wiring or leak/misattribute request metadata.

Overview
This PR propagates the gin.Context into auth validation calls so the service can attach masked API keys/access tokens, user.id, and team.id as OpenTelemetry attributes on the parent request span. It also standardizes proxy request logging by introducing logger.ProxyRequestFields (including client IP extraction) and adds helpers for masking tokens (keys.MaskToken) plus corresponding logger/telemetry field helpers, with a small generic constraint update to require teams expose TeamID().

Written by Cursor Bugbot for commit 57e6e27. This will update automatically on new commits. Configure here.

@jakubno jakubno marked this pull request as ready for review March 12, 2026 14:14
@ValentaTomas ValentaTomas removed their request for review March 12, 2026 23:45
@jakubno jakubno assigned sitole and unassigned bchalios Mar 13, 2026

//nolint:contextcheck // We use the gin request context to set attributes on the parent span.
telemetry.SetAttributes(ginCtx.Request.Context(),
telemetry.WithAPIKey(apiKey),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's directly call telemetry.WithMaskedAPIKey to make it extra safe.


//nolint:contextcheck // We use the gin request context to set attributes on the parent span.
telemetry.SetAttributes(ginCtx.Request.Context(),
telemetry.WithAPIKey(apiKey),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where you can then easily search for the API key? Does it make sense to also log api key ID?

@jakubno jakubno requested a review from sitole March 13, 2026 11:56

//nolint:contextcheck // We use the gin request context to set attributes on the parent span.
telemetry.SetAttributes(ginCtx.Request.Context(),
telemetry.WithMaskedAPIKey(apiKey),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point with change from telemetry.WithAPIKey to telemetry.WithMaskedAPIKey to pass already masked value and rename function in way that its ovious from name already. You probably don't want to send a raw api key/auth token to a logging library; it's a different scope that should not ever receive any sensitive values in the first place.

@jakubno jakubno requested review from sitole and removed request for dobrac March 17, 2026 05:55
@jakubno jakubno merged commit 3a4e831 into main Mar 17, 2026
36 checks passed
@jakubno jakubno deleted the chore/improve-identification-in-logs branch March 17, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants